from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .routers import communities, statistics, weather, predictions

# 创建 FastAPI 应用实例
app = FastAPI(
    title="Multi-view System for Bike-Sharing Flow Analysis API",
    description="Provide data statistics, geographic information, and prediction results for the frontend.",
    version="1.0.0",
)

origins = [
    "http://localhost:3000",
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,  # 允许访问的源
    allow_credentials=True, # 支持 cookie
    allow_methods=["*"],    # 允许所有方法
    allow_headers=["*"],    # 允许所有请求头
)

# 将不同的路由包含进来
app.include_router(communities.router)
app.include_router(statistics.router)
app.include_router(weather.router)
app.include_router(predictions.router)

@app.get("/")
def read_root():
    """一个简单的测试端点，确认服务器是否正常运行。"""
    return {"message": "欢迎使用共享单车分析系统 API！"}